package com.bridge.bridge_login;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;

import androidx.core.content.ContextCompat;

import com.bridge.bridge_login.databinding.AcLoginBinding;
import com.bridge.common.base.BaseActivity;
import com.bridge.common.route.RouteUtils;
import com.bridge.common.utils.ToastshowUtils;

/**
 * author : bridge.24
 * date   : 21.3.123:31
 * desc   :
 */
public class LoginActivity extends BaseActivity {
    private AcLoginBinding binding ;
    private String content;
    private Context mContext ;

    @Override
    protected int layoutId() {
        return R.layout.ac_login;
    }

    @Override
    protected void initView() {
        binding = getBind() ;
        mContext = this ;
        content = "<font size='14' color='#4e8ce6'>《用户协议》</font>";
        binding.tvYhxy.setText(Html.fromHtml("我已阅读并同意" + content));
    }

    @Override
    protected void setListenner() {
        binding.checkView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    binding.btnLogin.setTextColor(ContextCompat.getColor(mContext ,R.color.white));
                    binding.btnLogin.setBackground(ContextCompat.getDrawable(mContext ,R.drawable.btn_click_lv));
                    binding.btnLogin.setEnabled(true);
                }else{
                    binding.btnLogin.setTextColor(ContextCompat.getColor(mContext ,R.color.tv_normal));
                    binding.btnLogin.setBackground(ContextCompat.getDrawable(mContext ,R.drawable.bg_click_gray));
                    binding.btnLogin.setEnabled(false);
                }
            }
        });

        binding.btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str_zh = binding.etZh.getText().toString();
                String str_mm = binding.etMm.getText().toString();
                if(TextUtils.isEmpty(str_zh)){
                    ToastshowUtils.showToastSafe("账号不能为空");
                    return;
                }
                if(TextUtils.isEmpty(str_mm)){
                    ToastshowUtils.showToastSafe("密码不能为空");
                    return;
                }

                RouteUtils.turnToMainActivity();
                finish();
            }
        });
        binding.tvRegisn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                turnToActivity(RegisnActivity.class);
            }
        });
    }
}
